package cn.bo.cloud.opencv.web;


import cn.bo.cloud.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.TimeUnit;



@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RedisService redisService;

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/uri1")
    public String test01(){

        String key = "cn:bo:cloud:shorturl:test01";
        redisService.setCacheObject(key, "hello world" , 20L, TimeUnit.SECONDS);
        return "uri-1";

    }

    @RequestMapping("/uri2")
    public String test02(){
        String key = "cn:bo:cloud:shorturl:test01";
        String value = redisService.getCacheObject(key);

        return value != null ? value : "NULL";

    }

    @RequestMapping("/uri3")
    public String test03(){
        System.out.println("opencv uri3  request");

        String forObject = restTemplate.getForObject("http://shorturl/test/uri1", String.class);

        return "opencv-03+" + forObject;

    }

}
